﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width,height=device-height, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0,shrink-to-fit=no" />
<meta name="format-detection" content="telephone=no" />
<!--em标准js代码，请放在页面的最上方，前面最好不要再有JS代码或JS文件-->
<script type="text/javascript" src="/js/rem.js"></script>
<link type="text/css" rel="stylesheet" href="/css/css.css" />
<link type="text/css" rel="stylesheet" href="/css/style.css" />
<title>东易日盛装饰开业盛典</title>
</head>

<body>		
	
	<div class="header">
		<a href="javascript:history.go(-1)" class="backa"></a>

		<a href="/contract/contractAdd" class="adda"></a>
	</div>	

	<div class="main main2">
		<div class="wp1">
			<div class="wp2" style="min-height: 11rem;">

				<div class="t1">签约详情</div>
				
				<div class="p7_in">
					<div class="ti">合同编号</div>
					<input id="conCode" name="conCode" type="text" class="text" disabled>
				</div>
				<div class="p7_in">
					<div class="ti">客户编号</div>
					<input id="userId" name="userId" type="text" class="text">
				</div>
				<div class="p7_in">
					<div class="ti">客户姓名</div>
					<input id="userName" name="userName" type="text" class="text">
				</div>
				<div class="p7_in">
					<div class="ti">客户手机号码</div>
					<input id="mobile" name="mobile" type="text" class="text">
				</div>
				<div class="p7_in">
					<div class="ti">客户住址</div>
					<input id="address" name="address" type="text" class="text">
				</div>
				<div class="p7_in">
					<div class="ti">签约时间</div>
					<div class="mh_time">
						<input id="createTime1" name="createTime1" type="date" class="text">
						<span id="createTime" name="createTime" class="mh_val"></span>
					</div>					
				</div>
				<div class="p7_in">
					<div class="ti">专属设计师</div>
					<input id="desId" name="desId" type="text" class="text" disabled>
				</div>
				<div class="p7_in">
					<div class="ti">备注</div>
					<input id="remark" name="remark" type="text" class="textremark">
				</div>
				<span id="msg" class="p3_inp" style="color: red;text-align: center;border: none;"></span>


				<a href="javascript:;" class="go" id="bmBtn" onclick="submit();">确认</a>

			</div>
		</div>
	</div>

	<img src="/images/bodysd.jpg" alt="" class="sd">
</body>
<script type="text/javascript" src="/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/js/base.js"></script>
<script type="text/javascript" src="/js/popups.js"></script>
<script type="text/javascript">

	$(function () {
		getContractDetail();
	});

	function getContractDetail() {
		$.ajax({
			url: "/contract/contractDetail",
			method: "get",
			data: "",
			success: function (data) {
				$("#conCode").val(data.conCode)
				$("#userId").val(data.userId)
				$("#userName").val(data.userName)
				$("#mobile").val(data.mobile)
				$("#address").val(data.address)
				$("#createTime").text(data.createTime)
				$("#desId").val(data.desId)
				$("#remark").val(data.remark)
			}
		})
	}

	$("#userId").blur(function () {
		var userId = $("#userId").val();
		if(userId!=""){
			$.ajax({
				url: "/customer/getCustomerByUserId",
				method: "post",
				data: {userId:userId},
				success: function (data) {
					if (data.msg == 0){
						$("#msg").text("该客户不存在")
					}
					if (data.msg == 1){
						var cus = data.customer;
						console.log(cus.name)
						$("#userName").val(cus.name);
						$("#mobile").val(cus.mobile);
						/*$("#address").val(customer.address);*/
					}
				}
			})
		}
	})

	$("#mobile").blur(function () {
		var mobile = $("#mobile").val();
		if(mobile!=""){
			$.ajax({
				url: "/customer/getCustomerByMobile",
				method: "post",
				data: {mobile:mobile},
				success: function (data) {
					if (data.msg == 0){
						$("#msg").text("该手机号码未报名,请仔细确认")
					}
					if (data.msg == 1){
						var cus = data.customer;
						console.log(cus.name)
						$("#userName").val(cus.name);
						$("#userId").val(cus.userId);
						/*$("#address").val(customer.address);*/
					}
				}
			})
		}
	})

	function submit() {
		var flag=true;
		var conCode=$("#conCode").val();
		var userId=$("#userId").val();
		var userName=$("#userName").val();
		var mobile=$("#mobile").val();
		var address=$("#address").val();
		var createTime=$("#createTime").text();
		var desId=$("#desId").val();
		var remark=$("#remark").val();

		//非空验证
		if (!checkhDesId(desId)){flag=false;}
		if (!checkhCreateTime(createTime)){flag=false;}
		if (!checkaddress(address)){flag=false;}
		if (!checkmobile(mobile)){flag=false;}
		if (!checkUserName(userName)){flag=false;}
		//if (!checkUserId(userId)){flag=false;}
		if (!checkConCode(conCode)){flag=false;}

		if(flag){
			$.ajax({
				url:"/contract/contractModify",
				method:"post",
				data:{
					conCode:conCode,
					userId:userId,
					userName:userName,
					mobile:mobile,
					address:address,
					createTime:createTime,
					desId:desId,
					remark:remark,
				},
				success:function (data) {
					if(data>0){
						jqtoast("修改成功");
						setTimeout(function () {
							location.href="/contract"
						},2000)
					}
				}
			})
		} else {
			return ;
		}
	}

	//非空验证
	function checkConCode(conCode) {
		if(conCode==""){
			$("#msg").text("合同编号不为空");
			return false;
		} else {
			return true;
		}
	}

	/*function checkUserId(userId) {
		if(userId==""){
			$("#msg").text("客户编码不为空");
			return false;
		} else {
			return true;
		}
	}*/

	function checkUserName(userName) {
		if(userName==""){
			$("#msg").text("客户姓名不为空");
			return false;
		} else {
			return true;
		}
	}

	function checkmobile(mobile) {
		var mobileReg=/^1\d{10}$/;
		if(mobile==""){
			$("#msg").text("客户联系电话不为空");
			return false;
		}else if(!(mobileReg.test(mobile))){
			$("#msg").text("手机号码有误");
			return false;
		} else {
			return true;
		}
	}

	function checkaddress(address) {
		if(address==""){
			$("#msg").text("客户地址不为空");
			return false;
		} else {
			return true;
		}
	}

	function checkhCreateTime(createTime) {
		if(createTime==""){
			$("#msg").text("签约日期不为空");
			return false;
		} else {
			return true;
		}
	}

	function checkhDesId(desId) {
		if(desId==""){
			$("#msg").text("设计师编码不为空");
			return false;
		} else {
			return true;
		}
	}
</script>
</html>